package com.example.administrator.shzs.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 *  获取当前网络状态
 */
public class NetWorkUtils {

    private   Context context;


    public NetWorkUtils(Context context){
        this.context=context;
    }

    /**
     * 获取网络状态
     * @return true;false
     */
    public boolean getNetWorkState(){

        ConnectivityManager connectivityManager=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mobNetInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        NetworkInfo  wifiNetInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);


        if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {

            return false;//没网
        }
        return true;//有网
    }
}
